package com.yanghui.lingyue.data

import com.icedata.sika.bridge.SikaGroupContact
import com.icedata.sika.database.Column
import com.icedata.sika.database.Table
import java.util.*

/**
 * 群的数据对象
 * 在sika的bot类中会有一个群的
 *
 * @property groupID Long 群号
 * @property groupName String 群名
 * @property groupCache LinkedHashMap<String, Any> 一个用来装载群缓存的
 * @constructor 构造函数交由两个
 */
@Table(name = "[Group]", database = "", primaryKey = "groupID")
data class Group(

    @Column("groupID")
    var groupID: Long = 0,

    @Column("groupName")
    var groupName: String = "",

    val groupCache: LinkedHashMap<String, Any> = LinkedHashMap()
) {
    private val groupMemberList = LinkedList<Long>()
    lateinit var sikaGroup: SikaGroupContact

    /**
     * 注意！此函数必须在launcher.launch()以后才能调用！
     */
    fun refreshMember() {
        groupMemberList.clear()
        sikaGroup = SikaGroupContact(groupID)
        sikaGroup.getUsers().forEach {
            groupMemberList.add(it.id)
        }
    }
}